package cn.tedu.imop.marketing.controller;

import cn.tedu.imop.api.model.RestResult;
import cn.tedu.imop.api.model.RestResultUtils;
import cn.tedu.imop.common.constants.Constants;
import cn.tedu.imop.common.pojo.PageData;
import cn.tedu.imop.marketing.entity.Coupon;
import cn.tedu.imop.marketing.service.CouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Api(tags = "优惠卷管理")
@RestController
@RequestMapping(Constants.CONTROLLER_API_VERSION+"/coupon")
public class CouponController {
    private final CouponService couponService;
    public CouponController(CouponService couponService) {
        this.couponService = couponService;
    }
    @ApiOperation("创建优惠卷")
    @PostMapping
    public RestResult<Void> createCoupon(Coupon coupon) {
         couponService.createCoupon(coupon);
         return RestResultUtils.success();
    }

    @ApiOperation("优惠卷列表")
    @GetMapping
    public RestResult<PageData<Coupon>> getCouponList(Coupon coupon) {
        return RestResultUtils.success(couponService.getCouponList(coupon));
    }
}
